package io.renren.modules.pos.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.modules.emp.entity.EmployeeEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.pos.entity.PosEntity;
import io.renren.modules.pos.service.PosService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

@RestController
@RequestMapping("pos/pos")
public class PosController {
    @Autowired
    private PosService posService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("pos:pos:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = posService.queryPage(params);

//        int pageIndex = Integer.parseInt(String.valueOf(params.get("page")));
//        int pageSize = Integer.parseInt(String.valueOf(params.get("limit")));
//        String posname = String.valueOf(params.get("key"));
//        Page<PosEntity> page = new Page<>(pageIndex,pageSize);
//
//        // 通过调用自定义dao层实现
//        posService.selectByPosname(posname,page);

        return R.ok().put("page", page);
    }

    @GetMapping(value = "/num",produces = {"application/json;charset=UTF-8"})
    public List listNum(){
        return posService.listNum();
    }



    //根据工堆位逻辑名position进行分组查询
    @GetMapping(value = "/group",produces = {"application/json;charset=UTF-8"})
    public List listGroup(){
        return posService.listGroup();
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{pid}")
    @RequiresPermissions("pos:pos:info")
    public R info(@PathVariable("pid") String pid){
		PosEntity pos = posService.getById(pid);

        return R.ok().put("pos", pos);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("pos:pos:save")
    public R save(@RequestBody PosEntity pos){
		posService.save(pos);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("pos:pos:update")
    public R update(@RequestBody PosEntity pos){
		posService.updateById(pos);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("pos:pos:delete")
    public R delete(@RequestBody String[] pids){
		posService.removeByIds(Arrays.asList(pids));

        return R.ok();
    }

}
